Skip to content

Enhance logging tests and refactor log handling#333

Merged
ppinchuk merged 16 commits into
mainfrom
pp/log_unit_tests
Nov 15, 2025
Merged

Enhance logging tests and refactor log handling#333
ppinchuk merged 16 commits into
mainfrom
pp/log_unit_tests

Conversation

@ppinchuk
Copy link
Copy Markdown
Collaborator

@ppinchuk ppinchuk commented Nov 9, 2025

Pull Request Overview

Improve test coverage for the JSON exception file handler and refactor log record creation in tests. Introduce a configurable sleep duration for async log flushing to enhance performance and maintainability.

…s_logs.py to ensure _JsonExceptionFileHandler leaves pre-existing JSON content untouched while appending new exception entries.
…ies_logs.py to verify _JsonExceptionFileHandler.emit short-circuits cleanly when json.dumps raises TypeError, leaving the existing JSON file untouched.
…sonExceptionFileHandler recovers gracefully when the file contains invalid JSON, replacing it with valid content for the new record
…ileHandler behavior: the JSON output groups entries by module name. The test now checks the test_utilities_logs bucket, confirms the ValueError entry was recorded, and asserts the taskName matches the async task name.
…th a docstring in logs.py and replaced the hardcoded sleep values in __aexit__.
…Log.ASYNC_EXIT_SLEEP_SECONDS = 0.01 (restored afterward) so the test completes quickly.
Copilot AI review requested due to automatic review settings November 9, 2025 00:26
@ppinchuk ppinchuk requested a review from castelao as a code owner November 9, 2025 00:26
@ppinchuk ppinchuk self-assigned this Nov 9, 2025
@ppinchuk ppinchuk added enhancement Update to logic or general code improvements p-medium Priority: medium topic-python-general Issues/pull requests related to python labels Nov 9, 2025
@ppinchuk ppinchuk added this to the Finishing touches for OSS milestone Nov 9, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the logging test suite by adding comprehensive test coverage for COMPASS Ordinance logging utilities and introduces a configurable sleep constant to improve test performance.

  • Adds ASYNC_EXIT_SLEEP_SECONDS constant to LocationFileLog class for configurable async exit sleep timing
  • Introduces extensive test coverage for logging filters, formatters, handlers, and context managers
  • Implements a test fixture to speed up async tests by reducing sleep times

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
compass/utilities/logs.py Adds configurable ASYNC_EXIT_SLEEP_SECONDS constant to enable faster testing of async exit behavior
tests/python/unit/utilities/test_utilities_logs.py Adds comprehensive test coverage for logging components including filters, formatters, handlers, and context managers; introduces fixture to accelerate async tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@castelao castelao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding all these tests. The operations system I'm developing relies on the logs, so it is great to know that we can count on a robust logging.

Comment thread tests/python/unit/utilities/test_utilities_logs.py
@ppinchuk ppinchuk merged commit 7a93eb7 into main Nov 15, 2025
19 checks passed
@ppinchuk ppinchuk deleted the pp/log_unit_tests branch November 15, 2025 18:52
rajeee pushed a commit that referenced this pull request May 27, 2026
* Add extra tests

* Enhance async log listener test to capture emitted log records

* Add check to exception filter for non-exception records

* Refactor log record creation in tests to use a factory function

* Add helper fixture to attach ValueError exc_info to log records

* Refactor log record creation and exception handling in tests

* Rename log record helper functions for clarity and consistency

* Added test_json_exception_file_handler_existing_file in test_utilities_logs.py to ensure _JsonExceptionFileHandler leaves pre-existing JSON content untouched while appending new exception entries.

* Added test_json_exception_file_handler_emit_type_error in test_utilities_logs.py to verify _JsonExceptionFileHandler.emit short-circuits cleanly when json.dumps raises TypeError, leaving the existing JSON file untouched.

* Added test_json_exception_file_handler_invalid_json to verify that _JsonExceptionFileHandler recovers gracefully when the file contains invalid JSON, replacing it with valid content for the new record

* Updated test_location_file_log_async_context to match _JsonExceptionFileHandler behavior: the JSON output groups entries by module name. The test now checks the test_utilities_logs bucket, confirms the ValueError entry was recorded, and asserts the taskName matches the async task name.

* Introduced ASYNC_EXIT_SLEEP_SECONDS on LocationFileLog (default 3) with a docstring in logs.py and replaced the hardcoded sleep values in __aexit__.

* In test_location_file_log_async_context, temporarily set LocationFileLog.ASYNC_EXIT_SLEEP_SECONDS = 0.01 (restored afterward) so the test completes quickly.

* Add tests for empty handler

* Minor updates

* Use module-level fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Update to logic or general code improvements p-medium Priority: medium topic-python-general Issues/pull requests related to python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants